package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.facade.TaxRetailerInfoService;
import com.irdstudio.efp.rule.service.dao.TaxRetailerInfoDao;
import com.irdstudio.efp.rule.service.domain.TaxRetailerInfo;
import com.irdstudio.efp.rule.service.vo.TaxRetailerInfoVO;


/**
 * Service Impl: 个体户信息表服务实现
 * @author ligm
 * @date 2019-04-29 
 */
@Service("taxRetailerInfoService")
public class TaxRetailerInfoServiceImpl implements TaxRetailerInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxRetailerInfoServiceImpl.class);

	@Autowired
	private TaxRetailerInfoDao taxRetailerInfoDao;

   	/**
	 * 新增数据 
     * @param inTaxRetailerInfoVo
     * @return 
	 */
	public int insertTaxRetailerInfo(TaxRetailerInfoVO inTaxRetailerInfoVo) {
		logger.debug("当前新增数据为:"+ inTaxRetailerInfoVo.toString());
		int num = 0;
		try {
			TaxRetailerInfo taxRetailerInfo = new TaxRetailerInfo();
			beanCopy(inTaxRetailerInfoVo, taxRetailerInfo);
			num = taxRetailerInfoDao.insertTaxRetailerInfo(taxRetailerInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inTaxRetailerInfoVo
 	 * @return
	 */
	public int deleteByPk(TaxRetailerInfoVO inTaxRetailerInfoVo) {
		logger.debug("当前删除数据条件为:"+ inTaxRetailerInfoVo);
		int num = 0;
		try {
			TaxRetailerInfo taxRetailerInfo = new TaxRetailerInfo();
			beanCopy(inTaxRetailerInfoVo, taxRetailerInfo);
			num = taxRetailerInfoDao.deleteByPk(taxRetailerInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxRetailerInfoVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inTaxRetailerInfoVo
	 * @return 
	 */  
	public int updateByPk(TaxRetailerInfoVO inTaxRetailerInfoVo) {
		logger.debug("当前修改数据为:"+ inTaxRetailerInfoVo.toString());
		int num = 0;
		try {
			TaxRetailerInfo taxRetailerInfo = new TaxRetailerInfo();
			beanCopy(inTaxRetailerInfoVo, taxRetailerInfo);
			num = taxRetailerInfoDao.updateByPk(taxRetailerInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxRetailerInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param taxRetailerInfo
	 * @return 
	 */
	public TaxRetailerInfoVO queryByPk(TaxRetailerInfoVO inTaxRetailerInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxRetailerInfoVo);
		try {
			TaxRetailerInfo queryTaxRetailerInfo = new TaxRetailerInfo();
			beanCopy(inTaxRetailerInfoVo, queryTaxRetailerInfo);
			TaxRetailerInfo queryRslTaxRetailerInfo = taxRetailerInfoDao.queryByPk(queryTaxRetailerInfo);
			if (Objects.nonNull(queryRslTaxRetailerInfo)) {
				TaxRetailerInfoVO outTaxRetailerInfoVo = beanCopy(queryRslTaxRetailerInfo, new TaxRetailerInfoVO());
				logger.debug("当前查询结果为:"+ outTaxRetailerInfoVo.toString());
				return outTaxRetailerInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param taxRetailerInfo
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<TaxRetailerInfoVO> queryAllByLevelOne(TaxRetailerInfoVO taxRetailerInfoVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<TaxRetailerInfoVO> list = null;
		try {
			List<TaxRetailerInfo> taxRetailerInfos = taxRetailerInfoDao.queryAllByLevelOneByPage(taxRetailerInfoVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ taxRetailerInfos.size());
			pageSet(taxRetailerInfos, taxRetailerInfoVo);
			list = (List<TaxRetailerInfoVO>) beansCopy(taxRetailerInfos, TaxRetailerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param taxRetailerInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerInfoVO> queryAllByLevelTwo(TaxRetailerInfoVO taxRetailerInfoVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<TaxRetailerInfo> taxRetailerInfos = taxRetailerInfoDao.queryAllByLevelTwoByPage(taxRetailerInfoVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+taxRetailerInfos.size());
		List<TaxRetailerInfoVO> list = null;
		try {
			pageSet(taxRetailerInfos, taxRetailerInfoVo);
			list = (List<TaxRetailerInfoVO>) beansCopy(taxRetailerInfos, TaxRetailerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param taxRetailerInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerInfoVO> queryAllByLevelThree(TaxRetailerInfoVO taxRetailerInfoVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<TaxRetailerInfo> taxRetailerInfos = taxRetailerInfoDao.queryAllByLevelThreeByPage(taxRetailerInfoVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ taxRetailerInfos.size());
		List<TaxRetailerInfoVO> list = null;
		try {
			pageSet(taxRetailerInfos, taxRetailerInfoVo);
			list = (List<TaxRetailerInfoVO>) beansCopy(taxRetailerInfos, TaxRetailerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param taxRetailerInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerInfoVO> queryAllByLevelFour(TaxRetailerInfoVO taxRetailerInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxRetailerInfo> taxRetailerInfos = taxRetailerInfoDao.queryAllByLevelFourByPage(taxRetailerInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxRetailerInfos.size());
		List<TaxRetailerInfoVO> list = null;
		try {
			pageSet(taxRetailerInfos, taxRetailerInfoVo);
			list = (List<TaxRetailerInfoVO>) beansCopy(taxRetailerInfos, TaxRetailerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param taxRetailerInfo
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxRetailerInfoVO> queryAllByLevelFive(TaxRetailerInfoVO taxRetailerInfoVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxRetailerInfo> taxRetailerInfos = taxRetailerInfoDao.queryAllByLevelFiveByPage(taxRetailerInfoVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxRetailerInfos.size());
		List<TaxRetailerInfoVO> list = null;
		try {
			pageSet(taxRetailerInfos, taxRetailerInfoVo);
			list = (List<TaxRetailerInfoVO>) beansCopy(taxRetailerInfos, TaxRetailerInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
}
